home *** CD-ROM | disk | FTP | other *** search
/ c't freeware shareware 2001 January / CT_SW0101.ISO / pc / software / kommunik / multimed / snakcarb.sit / Snak 4.6.3 Carbon / Scripts / Dice < prev    next >
Text File  |  2000-06-10  |  2KB  |  63 lines

  1. # Kent Sorensen 06/09/00 This file contains an alias useful in online role playing games etc.
  2.  
  3. # /dice "number of dice" "number of sides" "modifier"
  4.  
  5. # in script : $0 : number of dice
  6. #             : $1 : number of sides
  7. #             : $2 : modifier
  8.  
  9. # output examples
  10. # /dice 2 6 0
  11. # <yournick> rolls 2 d 6 = 3,3 = 6
  12.  
  13. # /dice 2 6 10
  14. # <yournick> rolls 2 d 6 + 10 = 3,1 + 10 =  14
  15.  
  16. # A "gotcha" of the ircII language is that if you use the @ form instead of the
  17. # assign command, the parameters have no $ making it just 0 instead of $0
  18.  
  19. # use the @ form when you use the variable is an arithmetic expression like
  20. # this @eyes = eyes + 1
  21.  
  22. # the [] around some elements cause them to be 'evaluated' meaning that
  23. # the contents of variables are used instead of the name of the variable
  24.  
  25. alias dice {
  26.     ^assign dices $0
  27.     
  28.  # get a random number between zero and one less than $1
  29.      ^assign eyes $rand($1)  
  30.      
  31. # compensate for the zero base
  32.       @eyes = eyes + 1        
  33.        
  34.  # create output string and treat as string, not number      
  35.     ^assign outputString ${eyes}
  36.     @outputSum = eyes + [$2]
  37.     
  38.     
  39.  # the first dice was handled above, deal with the rest and build comma separated list
  40.        
  41.     ^assign repcnt $0
  42.     while ( repcnt > 1 )
  43.     {
  44.         ^assign eyes $rand($1)
  45.           @eyes = eyes + 1
  46.           
  47.  # concatenate output string as string, not number      
  48.         ^assign outputString $outputString,${eyes}
  49.           @outputSum = outputSum + eyes
  50.     
  51.         @repcnt = repcnt - 1
  52.     }
  53.     ^assign -repcnt
  54.     
  55.     if ([$2] > 0)
  56.     {
  57.         me rolls $0 d $1 + $2 = $outputString + $2 = $outputSum
  58.     }
  59.     {
  60.         me rolls $0 d $1 = $outputString = $outputSum
  61.     }
  62. }
  63.